<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<button onclick="sex()">根据身份证判断性别</button>
		<button onclick="no()">找出字符串中所有的no</button>
		<button onclick="email()">用截取的方式获取邮箱的用户/服务器名</button>
		<button onclick="birth()">根据身份证判断生日</button>
		<button onclick="email2()">用切割的方式获取邮箱的用户/服务器名</button>
		<button onclick="bigsmall()">将字符串首字母变成大写</button>
		<button onclick="nums()">计算字符串中中文、英文、数字和特殊符号的个数</button>
		<button onclick="nums2()">计算字符串中字符的个数</button>
		<script type="text/javascript">
			function sex(){
				var str="513030199810066717";
				var sex=str.slice(-2,-1);
				sex%2==1?console.log("这是一个男的"):console.log("这是一个女的");
			}
			
			
			function nums(){
				var str="hello world 你好世界!+1008611";
				var num=0,chinese=0,english=0,other=0;
				for(var i=0;i<str.length;i++){
					var code=str[i].charCodeAt();
					if(code>=48 && code<=57){
						num++;
					}else if((code>=65 && code<=90) || (code>=97 && code<=122)){
						english++;
					}else if(code>=19968 && code<=40869){
						chinese++;
					}else{
						other++;
					}
				}
				console.log("中文："+chinese+"个，英文："+english+"个，数字："+num+"个，其他："+other+"个");
			}
			
			
			function no(){
				var str="no zuo no die no can no bibi";
				var i=-1;
				while((i=str.indexOf("no",i+1))!=-1){
					console.log("找到了下标"+i+"为no");
				}
			}
			
			
			function email(){
				var email="631651604@qq.com";
				var i=email.indexOf("@");
				var numstr=email.slice(0,i);
				var addstr=email.slice(i+1);
				console.log("用户名为："+numstr);
				console.log("服务器为："+addstr);
			}
			
			
			function birth(){
				var id="513030199810066717";
				console.log("您的生日为："+id.substr(6,4)+"年"+id.substr(10,2)+"月"+id.substr(12,2)+"日");
			}
			
			
			function email2(){
				var email="631651604@qq.com";
				console.log("用户名为："+email.split("@")[0]);
				console.log("服务器为："+email.split("@")[1]);
			}
			
			function bigsmall(){
				var str="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Suscipit similique ipsum repellendus earum illum ut odio quibusdam recusandae beatae quo atque consequatur illo tempora veniam modi sint laudantium eos accusamus.";
				var arr=str.split(" ");
				console.log("原字符串为:"+str);
				for(var i=0,newstr="";i<arr.length;i++){
					newstr+=arr[i][0].toUpperCase()+arr[i].slice(1)+" ";
				}
				console.log("首字母变成大写后的字符串："+newstr);
			}
			
			
			function nums2(){
				var str="hello world today is a good day";
				var arr=[];
				for(var i=0;i<str.length;i++){
					if(arr[str[i]]===undefined){
						arr[str[i]]=1;
					}else{
						arr[str[i]]++;
					}
				}
				console.log("原字符串为："+str);
				console.log(arr);
			}
			
		</script>
	</body>
</html>
